package jwj8508.swing;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class InsertImage {
	  private static String url = "jdbc:oracle:thin:jwj8508/jwj8508@112.216.253.125:1521:XE";


	  public static void main(String[] args) throws Exception {
	    Connection conn = null;
	    InputStream fis = null;
	    try {
	        Class.forName("oracle.jdbc.driver.OracleDriver");
	        conn = DriverManager.getConnection(url);
	        conn.setAutoCommit(false);

	        String sql = "update movies set poster = ? where movno='307'";
	        PreparedStatement stmt = conn.prepareStatement(sql);
	       /* stmt.setString(1, "12.jpg");
	        stmt.setString(2, "test image");*/

	        File image = new File("f:/s.jpg"); 
	        fis = new FileInputStream(image);
	        int ilen=(int) image.length();
	        System.out.println(ilen);
	        System.out.println(fis);
	        stmt.setBinaryStream(1, fis, ilen);
	        stmt.execute();

	        System.out.println("this is upto b4 commit");   
	        conn.commit();
	    } catch (Exception e) {
	        e.printStackTrace();
	    } finally {
	        if (fis != null) {
	            fis.close();
	        }
	        if (conn != null && !conn.isClosed()) {
	            conn.close();
	        }
	    }
	  }
	}
